package com.iseastar.guojiang.team;

import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.TextView;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.consts.MsgID;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.logic.JSON;
import com.iseastar.guojiang.model.CourierTeamMemberApplyListBean;
import com.iseastar.guojiang.model.ReqResult;
import com.shouhuobao.station.R;
import com.shouhuobao.take.utils.DateUtils;
import com.shouhuobao.take.weight.CircularImage;

import droid.frame.utils.GlideUtil;
import droid.frame.utils.lang.Str;

/**
 * 战队队员申请详情
 * Created by lidandan on 2018/6/19.
 */
public class CourierTeamMemberApplyListDetailActivity extends BaseActivity2 implements View.OnClickListener {

    private CourierTeamMemberApplyListBean item = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        item = (CourierTeamMemberApplyListBean) getIntent().getSerializableExtra("item");
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.courier_team_member_apply_detail_activity);
        super.findViewById();
        getAppTitle().setCommonTitle("申请人详情");
        if (item != null) {
            CircularImage mCourierTitleImage = (CircularImage) findViewById(R.id.courier_title_image);
            TextView mCourierNameTV = (TextView) findViewById(R.id.courier_name_tv);
            TextView mJoinTimeTV = (TextView) findViewById(R.id.join_time_tv);
            TextView mCourierMessageTV = (TextView) findViewById(R.id.courier_message_tv);
            TextView mOrderQuantityTV = (TextView) findViewById(R.id.order_quantity_tv);
            TextView mCourierIntroTV = (TextView) findViewById(R.id.courier_intro_tv);
            findViewById(R.id.turn_down_tv).setOnClickListener(this);
            findViewById(R.id.consent_tv).setOnClickListener(this);
            GlideUtil.loadImage(getContext(), item.getImagePath(), R.drawable.setting_head_hover_default, mCourierTitleImage);

            if (Str.isEmpty(item.getName())) {
                mCourierNameTV.setText(item.getNickName() + "（）");
            } else {
                mCourierNameTV.setText(item.getNickName() + "（" + item.getName().substring(0, 1) + "师傅）");
            }
            mJoinTimeTV.setText(DateUtils.getTimeYMDHMSFormat().format(item.getCreateTime()).split(" ")[0] + " 申请加入");
            mCourierMessageTV.setText(item.getSex() + "，" + item.getProvinceName() + "人，" + item.getAge() + "岁   " + item.getScore() + "分");
            mOrderQuantityTV.setText("累计完成" + item.getTaskCount() + "单，本月总收入" + item.getTaskProfit() + "元");
            mCourierIntroTV.setText(item.getIntroduce());
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //拒绝
            case R.id.turn_down_tv:
                //status为3是拒绝
                AppHttp.getInstance().teamMemberCheck(item.getTeamId(), item.getId(), 3);
                break;
            //同意
            case R.id.consent_tv:
                //status为2是同意
                AppHttp.getInstance().teamMemberCheck(item.getTeamId(), item.getId(), 2);
                break;
        }

    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MsgID.team_member_check:
                cancelLoadingDialog();
                final ReqResult result = JSON.parser(msg.obj);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (checkLoginStatus(result)) {
                            finish();
                        } else {
                            showToast(result.getMessage());
                        }
                    }
                });
                return false;
            default:
                return super.handleMessage(msg);
        }
    }
}
